package ssau.knyazev.core;

public class B2Complex {

	protected float u0;
	protected float u1;
	protected float u2;
	protected float u3;
	
	public B2Complex() {	}
	
	public B2Complex(CComplex x){
		this.u0 = (x.getA()+x.getD())/2;
		this.u1 = (x.getA()-x.getD())/2;
		this.u2 = (x.getB()-x.getC())/2;
		this.u3 = (x.getB()+x.getC())/2;
	}
	
	public B2Complex(float x){
		this.u0 = x/2;
		this.u1 = x/2;
		this.u2 = 0;
		this.u3 = 0;
	}

	public B2Complex(float u0, float u1, float u2, float u3) {
		this.u0 = u0;
		this.u1 = u1;
		this.u2 = u2;
		this.u3 = u3;
	}
	
	public float getU0() {
		return u0;
	}

	public void setU0(float u0) {
		this.u0 = u0;
	}

	public float getU1() {
		return u1;
	}

	public void setU1(float u1) {
		this.u1 = u1;
	}

	public float getU2() {
		return u2;
	}

	public void setU2(float u2) {
		this.u2 = u2;
	}

	public float getU3() {
		return u3;
	}

	public void setU3(float u3) {
		this.u3 = u3;
	}

	public static B2Complex multyU0U2(B2Complex a, B2Complex b){
		return new B2Complex(2*a.u0*b.u0 - 2*a.u2*b.u2, 0, 2*a.u0*b.u2 + 2*a.u2*b.u0, 0);
	}
	
	public static B2Complex multyU1U3(B2Complex a, B2Complex b){
		return new B2Complex(0, 2*a.u1*b.u1 - 2*a.u3*b.u3, 0, 2*a.u1*b.u3 + 2*a.u3*b.u1);
	}
	
	public static B2Complex sum(B2Complex a, B2Complex b) {
		return new B2Complex(a.u0 + b.u0, a.u1 + b.u1, a.u2 + b.u2, a.u3 + b.u3);
	}
	
	public static B2Complex sumU0U2(B2Complex a, B2Complex b) {
		return new B2Complex(a.u0 + b.u0, 0, a.u2 + b.u2, 0);
	}
	
	public static B2Complex sumU1U3(B2Complex a, B2Complex b) {
		return new B2Complex(0, a.u1 + b.u1, 0, a.u3 + b.u3);
	}
	
	public static B2Complex sub(B2Complex a, B2Complex b) {
		return new B2Complex(a.u0 - b.u0, a.u1 - b.u1, a.u2 - b.u2, a.u3 - b.u3);
	}
	
	public static B2Complex subU0U2(B2Complex a, B2Complex b) {
		return new B2Complex(a.u0 - b.u0, 0, a.u2 - b.u2, 0);
	}
	
	public static B2Complex subU1U3(B2Complex a, B2Complex b) {
		return new B2Complex(0, a.u1 - b.u1, 0, a.u3 - b.u3);
	}
	
	
	public CComplex getCComplex(){
		return new CComplex( (u0 + u1), (u2 + u3), (u3 - u2), (u0 - u1) );
	}
	
	public Complex getComplex(){
		float re = 2*u1;
		float im = 2*u3;
		return new Complex(re, im);
	}
	
	@Override
	public String toString() {
		String str = String.format("(%.2f %.2f %.2f %.2f)", u0, u1, u2, u3);
		return str;
	}
	
	@Override
	public B2Complex clone(){
		return new B2Complex(u0, u1, u2, u3);
	}
	
}
